import copy
s = "thefoobarman"
words = ["foo","bar"]
first_word = copy.deepcopy(words)
m = len(s)
n, l = len(words[0]), len(words)
print(m,n,l)
if m < n*l :
    print([])
i, j = 0, 0
lst = []
word = []
window = 0

'''
思想可以，代码不知道怎么实现
'''


while j< m:
    remaining_words = words  # 使用临时列表来存储剩余的单词
    for p in range(len(remaining_words)):
        if s[j:j + n] == remaining_words[p]:
            word.append(remaining_words[p])
            remaining_words.remove(remaining_words[p])  # 从临时列表中移除匹配的单词
            break
    j += n
    window = j - i
    if window == n * l and len(remaining_words)==0:
        lst.append(i)
        i += n
        j = i
        words = first_word
        word = []
    elif window == n * l and len(remaining_words)!=0:
        i += n
        j = i
        words = first_word
        word = []
print(lst)
print('-'*40)
print(first_word)